<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>客户发展计划的添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
        .layui-form-item .layui-input-inline{
            width: 300px;
        }
    </style>
</head>

<body>
<div class="x-body">
    <form class="layui-form">

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>计划的编码
            </label>
            <div class="layui-input-inline">
                <input type="text" name="planCode"  lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>计划者姓名
            </label>
            <div class="layui-input-inline">
                <input id="name" type="text" name="plannerName"  required="" lay-verify="required"
                       autocomplete="off" class="layui-input" readonly th:value="${session.get('emplName')}">
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>
        <div class="layui-form-item">
            <label for="start" class="layui-form-label">
                <span class="x-red">*</span>计划月份
            </label>
            <div class="layui-input-inline">
                <!--                  <input type="text" id="phone" name="emplPhone" required="" lay-verify="phone"-->
                <!--                  autocomplete="off" class="layui-input" th:value="111">-->
                <input class="layui-input" placeholder="月份" name="planMonth" id="start"
                       required="" >
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>状态
            </label>
            <div class="layui-input-inline">
                <input type="radio" name="planStatus" value="1" title="已提交">
                <input type="radio" name="planStatus" value="2" title="已通过" >
                <input type="radio" name="planStatus" value="3" title="已创建" >
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>备注
            </label>
            <div class="layui-input-inline">
                <textarea name="planRemark" placeholder="请输入计划内容信息" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                添加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['laydate','form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate;



        //监听提交
        form.on('submit(add)', function(data){

            var param = data.field;
            param.planType = 2;
            console.log(param)
            // 添加到param中

            $.ajax({
                type: "post",// http请求方法
                url:"/customer/add/do",// 后端的接口
                data: param,// 传递到后端的数据
                dataType: "json", // 后端返回的数据类型
                success: function (res) {// 服务器成功响应之后对应的逻辑
                    if (res.code === 200){
                        layer.alert(res.msg, {icon: 6},function () {
                            // 重载表格
                            parent.tableIns.reload();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }

                }
            });

            return false;
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        // 获取数据
        $.ajax({
            type: "post",// http请求方法
            url:"/customer/list/data",// 后端的接口
            dataType: "json", // 后端返回的数据类型
            async: false, // 异步转同步
            success: function (res) {// 服务器成功响应之后对应的逻辑
                if (res.code === 200){
                    // console.log(res)
                    // 清空容器
                    $("select[name=plannerName]").empty();
                    $(res.data).each(function () {
                        var option = $('<option value="'+this.plannerName+'">'+this.plannerName+'</option>');
                        $("select[name=plannerName]").append(option);
                    })
                    // 重新渲染表单
                    form.render();
                }
            }
        });



    });
</script>

</body>

</html>